package com.ask.forMe.controller.business;

import com.ask.forMe.model.entity.Result;
import com.ask.forMe.service.ScoreService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/score")
@Slf4j
@Tag(name = "评分接口")
public class ScoreController {
    @Autowired
    private ScoreService scoreService;

    /**
     * 新增或跟新评分
     *
     * @param userId
     * @param itemId
     * @param score
     * @return
     */
    @PostMapping("/update")
    @Operation(summary = "跟新评分")
    public Result addOrUpdateScore(Long userId, Long itemId, Double score, int type) {
        scoreService.addOrUpdateScore(userId, itemId, score, type);
        log.info("用户{}对商品{}跟新评分为{}", userId, itemId, score);
        return Result.success();
    }
}
